import com.pbking.util.eventHandling.EventBroadcaster;
import com.pbking.logging.LogObject;
import com.pbking.logging.LogEvent;

/**
 * @author Jason Crist
 */
class com.pbking.logging.Logger extends EventBroadcaster {

	// VARIABLES //////////	

	public static var TRACE_LEVEL:Number = FINEST;
	private static var instance:Logger;

	// log levels

	public static var FATAL:Number = 1;
	public static var SEVERE:Number = 2;
	public static var WARNING:Number = 3;
	public static var INFO:Number = 4;
	public static var FINE:Number = 5;
	public static var FINER:Number = 6;
	public static var FINEST:Number = 7;
	
	// CONSTRUCTION //////////
	
	/**
	 * @return singleton instance of ComponentFactory
	 */
	public static function getInstance() : Logger {
		if (instance == null)
			instance = new Logger();
		return instance;
	}
	
	private function Logger() {
		//nothing here
	}
	
	// PUBLIC STATIC FUNCTIONS //////////
	
	// specific logging functions 
	
	/**
	 * logs FINEST
	 */
	public static function finest(message, className:String, methodName:String){
		getInstance().log(message, FINEST, className, methodName);
	}

	/**
	 * logs FINEST
	 */
	public static function debug(message, className:String, methodName:String){
		getInstance().log(message, FINEST, className, methodName);
	}

	/**
	 * logs FINER
	 */
	public static function finer(message, className:String, methodName:String){
		getInstance().log(message, FINER, className, methodName);
	}
	
	/**
	 * logs FINE
	 */
	public static function fine(message, className:String, methodName:String){
		getInstance().log(message, FINE, className, methodName);
	}
	
	/**
	 * logs INFO
	 */
	public static function info(message, className:String, methodName:String){
		getInstance().log(message, INFO, className, methodName);
	}
	
	/**
	 * logs WARNING
	 */
	public static function warning(message, className:String, methodName:String){
		getInstance().log(message, WARNING, className, methodName);
	}
	
	/**
	 * logs WARNING
	 */
	public static function warn(message, className:String, methodName:String){
		getInstance().log(message, WARNING, className, methodName);
	}
	
	/**
	 * logs SEVERE
	 */
	public static function severe(message, className:String, methodName:String){
		getInstance().log(message, SEVERE, className, methodName);
	}
	
	/**
	 * logs SEVERE
	 */
	public static function error(message, className:String, methodName:String){
		getInstance().log(message, SEVERE, className, methodName);
	}
	
	/**
	 * logs FATAL
	 */
	public static function fatal(message, className:String, methodName:String){
		getInstance().log(message, FATAL, className, methodName);
	}

	// PUBLIC FUNCTIONS //////////
	
	public function log(message, severity:Number, className:String, methodName:String){
		logObject(new LogObject(message, severity, className, methodName));
	}
	
	public function logObject(logObj:LogObject){
		dispatch(new LogEvent(logObj));

		if(TRACE_LEVEL >= logObj.severity)
			trace(logObj.toString());
	}
	
		
}